package com.library.controller;

import com.library.entity.Booktype;
import com.library.service.IBooktypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 至尊伍人组
 * @since 2018-09-30
 */
@Controller
@RequestMapping ( "/booktype" )
public class BooktypeController {

    @Autowired
    IBooktypeService booktypeService;

    /**
     * 添加新的图书种类
     *
     * @param booktype 待加入的图书种类
     * @return
     */
    @PostMapping ( "/add" )
    public String add( Booktype booktype ) {

        booktypeService.insert(booktype);
        return "redirect:/admin/booktypemanager";
    }

    /**
     * 根据图书种类的编号ID，删除指定的图书分类，同时还有删除该分类下的所有图书
     *
     * @param typeId
     * @return
     */
    @RequestMapping ( "/del" )
    public String del( int typeId ) {

        booktypeService.deleteById(typeId);
        return "redirect:/admin/booktypemanager";

    }

    /**
     * 用于更新图书种类的信息
     *
     * @param booktype 需要更新的实体
     * @return
     */
    @RequestMapping ( "/update" )
    public String update( Booktype booktype ) {

        booktype.updateById();

        return "redirect:/admin/booktypemanager";
    }

}

